package com.example.mvpdemo.base;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;

import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

import com.example.mvpdemo.exception.CrashHandler;

import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.unit.Subunits;
import xcrash.XCrash;


/**
 * @author:created by njb
 * 时间:2019/3/8 15 03
 * 描述:
 */
public class App  extends MultiDexApplication {
    //全局Context
    private static Context mContext;
    private static App mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext =  getApplicationContext();
       // initCrash();
        initAutoSize();
        initXCrash();
    }

    private void initXCrash() {
        XCrash.init(this);
    }

    private void initAutoSize() {
        AutoSizeConfig.getInstance().
                setDesignHeightInDp(375).
                setDesignWidthInDp(667).
                getUnitsManager()
                .setSupportSubunits(Subunits.PT);
    }

    private void initCrash() {
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(mContext);
    }



    public App() {
        mInstance = this;
    }

    public static Context getContext() {
        return mContext;
    }

    public static App the() {
        return mInstance;
    }



    /**
     * 设置APP应用字体不缩放
     */
    private void initconfig() {
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
    }



    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}
